﻿<Page
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
	  xmlns:System="clr-namespace:System;assembly=mscorlib"
	  xmlns:v="clr-namespace:MovieRental_Presentation.Validation"
	  x:Class="MovieRental_Presentation.CustomerDetails" 
      d:DesignWidth="1024" d:DesignHeight="600"
      mc:Ignorable="d"
      WindowTitle="Movie Rental"
	  MinWidth="900"
	  MinHeight="600" 
      ShowsNavigationUI="False">

	<Grid Background="{StaticResource backgroundBrush}">
    	<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*"/>
			<ColumnDefinition Width="250"/>
		</Grid.ColumnDefinitions>
		<Border BorderThickness="{StaticResource borderThickness}" Padding="{StaticResource borderPadding}" Margin="8" CornerRadius="{StaticResource borderCornerRadius}" BorderBrush="{StaticResource borderBrush}" Grid.Column="1">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="*"/>
				</Grid.RowDefinitions>
				<StackPanel Grid.Row="0">
					<Label Content="Menu" HorizontalAlignment="Center" Style="{StaticResource MenuLabelStyle}"/>
					<Button x:Name="dashboardButton" Content="Dashboard" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="dashboardButton_Click"/>
					<Button x:Name="customersButton" Content="Customers" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="customersButton_Click"/>
					<Button x:Name="moviesButton" Content="Movies" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="moviesButton_Click"/>
					<Button x:Name="statisticsButton" Content="Statistics" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="statisticsButton_Click"/>
				</StackPanel>
				<Frame Content="Frame" Grid.Row="1" Source="/MovieRental.Presentation;component/Cart.xaml" NavigationUIVisibility="Hidden"/>
			</Grid>
		</Border>
    	<Border BorderBrush="{StaticResource borderBrush}" BorderThickness="{StaticResource borderThickness}" Margin="8" Padding="{StaticResource borderPadding}" CornerRadius="{StaticResource borderCornerRadius}">
    		<Grid Margin="0">
    			<Grid.RowDefinitions>
    				<RowDefinition Height="Auto"/>
    				<RowDefinition Height="220"/>
    				<RowDefinition Height="Auto"/>
    				<RowDefinition Height="Auto"/>
    				<RowDefinition Height="*" />
    			</Grid.RowDefinitions>
    			<Label Content="Customer Details" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource MenuLabelStyle}"/>
    			<Button x:Name="backButton" Content="Back" HorizontalAlignment="Left" Width="60" Click="backButton_Click" Margin="8,8,0,0" VerticalAlignment="Top"/>
    			<Grid Grid.Row="1">
    				<Grid.RowDefinitions>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="*"/>
    					<RowDefinition Height="*"/>
    				</Grid.RowDefinitions>
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="Auto"/>
    					<ColumnDefinition Width="Auto" />
    					<ColumnDefinition Width="Auto"/>
    					<ColumnDefinition Width="Auto" />
    					<ColumnDefinition/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
					<StackPanel Grid.Column="0" Margin="8" Grid.RowSpan="6">
						<Button x:Name="assignButton" Height="60" Width="60" Margin="0,0,0,8" Content="Assign" Click="assignButton_Click"/>
						<Button Height="60" Width="60" Margin="0,0,0,8" Content="Edit" Name="editButton" Click="editButton_Click" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource booleanToVisibilityConverter}}" />
						<Button Height="60" Width="60" Margin="0" Content="Delete" Name="deleteButton" Click="deleteButton_Click" />
					</StackPanel>
					<TextBlock Grid.Column="2" Margin="0" Text="First Name" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
					<TextBlock Grid.Column="2" Margin="0" Text="Last Name" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Center"/>
					<TextBlock Grid.Column="2"  Text="Email" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" Grid.Row="2" VerticalAlignment="Center"/>
					<TextBlock Grid.Column="2"  Text="Phone No" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" Grid.Row="3" VerticalAlignment="Center"/>
					<TextBlock Grid.Column="2"  Text="Spent Money" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" Grid.Row="4" VerticalAlignment="Center"/>
					<TextBlock Grid.Column="2"  Text="Returned Editions" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" Grid.Row="5" VerticalAlignment="Center"/>
					<Border BorderBrush="{StaticResource borderBrush}" BorderThickness="{StaticResource borderThickness}" Margin="0,8,8,8" Grid.RowSpan="6" HorizontalAlignment="Right" Grid.Column="1" Width="2"/>
					<TextBox x:Name="firstNameTextBox" Grid.Column="3" Margin="8,0" VerticalAlignment="Center" Grid.ColumnSpan="2"  IsReadOnly="{Binding Path=IsReadOnly, Mode=OneWay}" Style="{StaticResource InputTextBoxStyle}">
						<TextBox.Text>
							<Binding Path="Customer.Entity.FirstName" Mode="TwoWay">
								<Binding.ValidationRules>
									<v:RequiredValidationRule ValidatesOnTargetUpdated="True"/>
								</Binding.ValidationRules>
							</Binding>
						</TextBox.Text>
					</TextBox>
                    <TextBox x:Name="lastNameTextBox" Grid.Column="3" Margin="8,0" Grid.Row="1" VerticalAlignment="Center" IsHitTestVisible="True" Grid.ColumnSpan="2" IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                    	<TextBox.Text>
							<Binding Path="Customer.Entity.LastName" Mode="TwoWay">
								<Binding.ValidationRules>
									<v:RequiredValidationRule ValidatesOnTargetUpdated="True"/>
								</Binding.ValidationRules>
							</Binding>
						</TextBox.Text>
                    </TextBox>
                    <TextBox x:Name="emailTextBox" Grid.Column="3" Margin="8,0" Grid.Row="2" VerticalAlignment="Center" Grid.ColumnSpan="2"  IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                    	 <TextBox.Text>
							<Binding Path="Customer.Entity.Email" Mode="TwoWay">
								<Binding.ValidationRules>
									<v:EmailValidationRule ValidatesOnTargetUpdated="True"/>
								</Binding.ValidationRules>
							</Binding>
						</TextBox.Text>
                    </TextBox>
                    <TextBox x:Name="phoneNoTextBox" Grid.Column="3" Margin="8,0" Grid.Row="3" VerticalAlignment="Center" Grid.ColumnSpan="2"  IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                    	<TextBox.Text>
							<Binding Path="Customer.Entity.PhoneNo" Mode="TwoWay">
								<Binding.ValidationRules>
									<v:PhoneNoValidationRule ValidatesOnTargetUpdated="True"/>
								</Binding.ValidationRules>
							</Binding>
						</TextBox.Text>
                    </TextBox>
					<TextBlock Grid.Column="3" HorizontalAlignment="Left" Margin="8,0" Grid.Row="4" TextWrapping="Wrap" Text="{Binding StringFormat=\{0:c\}, Path=Customer.SpentMoney}" Foreground="{StaticResource inputBoxBrush}" VerticalAlignment="Center" FontSize="{StaticResource infoTextSize}"/>
					<TextBlock Text="{Binding Customer.ReturnedEditions}" Grid.Column="3" HorizontalAlignment="Right" Margin="8,0" Grid.Row="5" TextWrapping="Wrap" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" VerticalAlignment="Center"/>
					<StackPanel Grid.Column="5" Grid.Row="0" Grid.RowSpan="4" Width="150" Margin="0,0,0,3.271">
						<Label Content="Discount" HorizontalAlignment="Center" Style="{StaticResource MenuLabelStyle}"/>
						<TextBlock Text="{Binding Path=Customer.PersonalDiscountValue, StringFormat=\{0\}%}" HorizontalAlignment="Center" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource dialogGiantTitleTextSize}"/>
					</StackPanel>
					<Button Content="Apply" Grid.Column="5" Margin="8,0" Grid.Row="4" VerticalAlignment="Center" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource boolToVisibilityReverseConverter}}" Name="applyButton" Click="applyButton_Click" />
                    <Button Content="Cancel" Margin="8,0" Grid.Row="5" Grid.Column="5" VerticalAlignment="Center" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource boolToVisibilityReverseConverter}}" Name="cancelEditButton" Click="cancelEditButton_Click" />
					<Grid Grid.Column="4" Margin="8,0" Grid.Row="4" Grid.RowSpan="2" >
						<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
							<TextBlock Text="Must return" VerticalAlignment="Center" Foreground="{StaticResource inputBoxBrush}" HorizontalAlignment="Left" FontSize="32">
							</TextBlock>
							<TextBlock Text="{Binding Path=Customer.MustReturnMoney, StringFormat=\{0:c\}}" VerticalAlignment="Center" Foreground="{StaticResource inputBoxBrush}" HorizontalAlignment="Right" Margin="8,0" FontSize="32"></TextBlock>
						</StackPanel>
					</Grid>
    			</Grid>
				<Border BorderBrush="{StaticResource borderBrush}" BorderThickness="1" Margin="8,0" Grid.Row="2" VerticalAlignment="Center" Height="2"/>
    			<Label Content="Loans" HorizontalAlignment="Center" Grid.Row="3" Margin="0,8" Style="{StaticResource MenuLabelStyle}"/>
    			<Grid Grid.Row="4" Margin="8,0">
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
    				<DataGrid x:Name="loanCartsDataGrid" Margin="0,0,4,0" ItemsSource="{Binding Carts}" AutoGenerateColumns="False" IsReadOnly="True">
    					<DataGrid.Columns>
    						<DataGridTextColumn Binding="{Binding Entity.LoanDate, StringFormat=\{0:d\}}" Header="Loan Date" Width="*"/>
    						<DataGridTextColumn Binding="{Binding CartDiscountValue, StringFormat=\{0\}%}" Header="Cart Discount" Width="*"/>
    						<DataGridTextColumn Binding="{Binding NotReturnedLoans}" Header="Not Returned Loans" Width="*"/>
    					</DataGrid.Columns>
    				</DataGrid>
    				<Grid Grid.Column="1" Margin="4,0,0,0" Visibility="{Binding SelectedIndex, Converter={StaticResource indexVisibilityConverter}, ElementName=loanCartsDataGrid}">
    					<Grid.ColumnDefinitions>
    						<ColumnDefinition Width="*"/>
    						<ColumnDefinition Width="*"/>
    					</Grid.ColumnDefinitions>
    					<Grid.RowDefinitions>
    						<RowDefinition Height="*"/>
    						<RowDefinition Height="30"/>
    					</Grid.RowDefinitions>
    					<DataGrid x:Name="loansDataGrid" Grid.ColumnSpan="2" Margin="0,0,0,8" ItemsSource="{Binding ElementName=loanCartsDataGrid, Path=SelectedItem.Loans}" AutoGenerateColumns="False" MaxWidth="300">
    						<DataGrid.Columns>
    							<DataGridTextColumn Binding="{Binding MovieTitle}" Header="Movie" Width="*"/>
    							<DataGridTextColumn Binding="{Binding MediaTypeName}" Header="Media Type" Width="*"/>
    							<DataGridTextColumn Binding="{Binding Entity.PricePerDay, StringFormat=\{0:c\}}" Header="Price Per Day" Width="*"/>
							</DataGrid.Columns>
    					</DataGrid>
    					<Button x:Name="returnButton" Content="Return" Grid.Row="1" Margin="0,0,8,0" IsEnabled="{Binding SelectedIndex, Converter={StaticResource selectedIndexToBoolConverter}, ElementName=loansDataGrid}" Click="returnButton_Click"/>
    					<Button x:Name="returnAllButton" Content="Return all" Grid.Row="1" Margin="8,0,0,0" Grid.Column="1" Click="returnAllButton_Click"/>
    				</Grid>
					
					
    			</Grid>
    		</Grid>
    	</Border>
        
    </Grid>
</Page>